package org.misty.seckill.redis;

public interface KeyPrefix {
  KeyPrefix EMPTY = new EmptyPrefix();

  int getExpiryInSec();

  String getPrefix();


  class EmptyPrefix implements KeyPrefix {
    @Override
    public int getExpiryInSec() {
      return 0;
    }

    @Override
    public String getPrefix() {
      return "";
    }
  }

  default String realKey(String key) {
    var prefix = this;
    String realKey;
    if (prefix == KeyPrefix.EMPTY) {
      realKey = key;
    } else {
      realKey = prefix.getPrefix() + key;
    }
    return realKey;
  }
}
